package com.deshan.websys.code.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.deshan.websys.code.mapper.UmsRoseMapper;
import com.deshan.websys.code.mapper.UmsUserMapper;
import com.deshan.websys.code.model.UmsRose;
import com.deshan.websys.code.model.UmsUser;
import com.deshan.websys.code.service.UmsRoseService;
import com.deshan.websys.code.service.UmsUserService;
import com.deshan.websys.code.utils.BeanUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UmsRoseServiceImpl implements UmsRoseService {
    @Resource
    UmsRoseMapper umsRoseMapper;
    @Override
    public int saveorupdate(UmsRose umsRose) {

        Integer id=umsRose.getId();
        int result=0;
        if(id==null){
            result=  umsRoseMapper.insert(umsRose);
        }else{
            UmsRose descUmsRose=umsRoseMapper.selectById(id);
            try{
                BeanUtil.copyNotNullProperties(descUmsRose,umsRose);
                result=  umsRoseMapper.updateById(descUmsRose);
            }catch (Exception ex){

            }

        }
        return  result;

    }

    @Override
    public int delete(Integer id) {
        int result=0;
        try{
            result=   umsRoseMapper.deleteById(id);
        }catch (Exception ex){

        }

        return result;
    }

    @Override
    public List<UmsRose> findUserByRose(String rose) {
        QueryWrapper<UmsRose> queryWrapper =new QueryWrapper<>();
        queryWrapper.eq("rose", rose);
        List<UmsRose> listrose=umsRoseMapper.selectList(queryWrapper);
        return listrose;
    }
    @Override
    public  List<UmsRose> getRose() {
        QueryWrapper<UmsRose> queryWrapper =new QueryWrapper<>();

        List<UmsRose> umsUserlist=umsRoseMapper.selectList(queryWrapper);
        return umsUserlist;
    }

}
